package com.wuyangnju.lj.callcenter.model.customer;

public class Customer {
	// customer property
	private double arrivalTime; // time when arrive, via Sim.time(), single use
	private double serviceTime; // service time, via random gen
	private double renegeTime; // patient time, via random gen

	// customer state
	private CustomerState state;

	// for statistic
	public int fromBuffer = -1;

	private double waitTime; // waiting time, via buffer waiting
	private boolean delayed;
	private boolean reneged;
	private boolean served;

	public Customer(double arrivalTime, double serviceTime, double renegeTime) {
		this.arrivalTime = arrivalTime;
		this.serviceTime = serviceTime;
		this.renegeTime = renegeTime;

		state = CustomerState.JUST_ARRIVED;
		delayed = false;
		reneged = false;
		served = false;
	}

	public double getServiceTime() {
		return serviceTime;
	}

	public double getRenegeTime() {
		return renegeTime;
	}

	public double getWaitTime() {
		return waitTime;
	}

	public boolean isDelayed() {
		return delayed;
	}

	public boolean isReneged() {
		return reneged;
	}

	public boolean isServed() {
		return served;
	}

	public void joinQueue() {
		state = CustomerState.IN_QUEUE;
		delayed = true;
	}

	public void getService(double t) {
		state = CustomerState.IN_SERVICE;
		waitTime = t - arrivalTime;
	}

	public void depart() {
		state = CustomerState.HAS_GONE;
		served = true;
	}

	public void renege(double t) {
		state = CustomerState.HAS_GONE;

		waitTime = t - arrivalTime;
		reneged = true;
	}

	public boolean isInBuffer() {
		return CustomerState.IN_QUEUE == state;
	}

}
